# -*- coding: utf-8 -*-
import json

import requests
import qiniu
from qiniu import QiniuMacAuth, http, config

# Please paste your ak and sk here.
access_key = 'wkJupck8Ylduede0ny9KSsIG4vqwDkelgBfejKSv'
secret_key = 'i4UrEdihv93LUun8MMG_OCAcGQHwPU6ZiHq5ijMg'
auth = QiniuMacAuth(access_key, secret_key)

def _post_with_qiniu_mac(url, data, auth):
    qn_auth = qiniu.auth.QiniuMacRequestsAuth(auth) if auth is not None else None
    timeout = config.get_default('connection_timeout')
    try:
        r = requests.post(
            url,
            json=data,
            auth=qn_auth,
            timeout=timeout,
        )
        print(r.json())
    except Exception as e:
        return None, http.ResponseInfo(None, e)
    return http.__return_wrapper(r)
def asr_request(data):
    url = "http://yitu-audio.qiniuapi.com/v2/asr"
    body = {
        "audioUrl": data,
    }
    ret, res = _post_with_qiniu_mac(url, body, auth)
    return ret, res

if __name__ == '__main__':
    audio_url = "http://103.142.139.57.wz4.cc/simcode/simcode/files/newvoice261685970259070.wav"
    ret, res = asr_request(audio_url)
    headers = {"code": res.status_code, "reqid": res.req_id, "xlog": res.x_log}
    print(json.dumps(headers, indent=4, ensure_ascii=False))